/*
    会员管理:地址管理
 */
$(function () {
    let userId = getQueryString("userId");
    let url = '../address/list';
    if (userId) {
        url += '?userId=' + userId;
    }
    $("#jqGrid").Grid({
        url: url,
        colModel: [
            {label: 'id', name: 'id', index: 'id', key: true, hidden: true},
            {label: '地址编号', name: 'id', index: 'id', width: 30},
            {label: '用户编号', name: 'userId', index: 'userId', width: 40},
            {label: '收货人', name: 'contactName', index: 'contactName', width: 50},
            {label: '手机', name: 'mobile', index: 'mobile', width: 50},
            {label: '省', name: 'province', index: 'province', width: 80},
            {label: '市', name: 'city', index: 'city', width: 80},
            {label: '区', name: 'county', index: 'county', width: 80},
            {label: '详细收货地址', name: 'address', index: 'address', width: 150},
            {
                label: '是否默认地址', name: 'isDefault', index: 'isDefault', width: 50,
                formatter: function (value) {
                    if (value == 1) {
                        return '默认地址';
                    } else {
                        return '';
                    }
                }
            },
            {label: '邮编', name: 'postCode', index: 'postCode', width: 80}]
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        q: {
            userId: '',
            name: '',
            phone: ''
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {
                    'userId': vm.q.userId,
                    'phone': vm.q.phone,
                    'name': vm.q.name
                },
                page: page
            }).trigger("reloadGrid");
        },
        reloadSearch: function() {
            vm.q = {
                name: '',
                userId: '',
                phone:''
            }
            vm.reload();
        },
        del: function (event) {
            var ids = getSelectedRows("#jqGrid");
            if (ids == null) {
                return;
            }
            let id=ids[0];
            console.log(id);
            confirm('确定要删除选中的记录？', function () {
                Ajax.request({
                    type: "GET",
                    url: "../address/delete/"+id,
                    contentType: "application/json",
                    // params: JSON.stringify(ids),
                    successCallback: function () {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    }
                });
            });
        }
    }
});